package com.coderush.admin.sys.dao;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.coderush.admin.core.common.PageResult;
import com.coderush.admin.sys.mapper.DepartmentMapper;
import com.coderush.admin.sys.model.entity.Company;
import com.coderush.admin.sys.model.entity.Department;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Repository;

/**
 * PackageName com.coderush.admin.sys.dao
 *
 * @Author Eason
 * @Version v1.0
 * @ClassName DepartmentDao
 * @Date 2025/8/25
 * @Description TODO
 */
@Repository
@AllArgsConstructor
public class DepartmentDao {

    private final DepartmentMapper departmentMapper;


    /**
     * 分页查询
     */
    public Page<Department> findByPage(Page<Department> page, String deptName) {
        return departmentMapper.findByPage(page, deptName);
    }

    /**
     * 添加部门
     *
     * @param department 数据模型
     * @return true:添加成功,false:添加失败
     */
    public int add(Department department) {
        return departmentMapper.insert(department);
    }

    /**
     * 根据部门编码查询
     */
    public Department getByDeptCode(String deptCode) {
        return departmentMapper.getByDeptCode(deptCode);
    }

    /**
     * 根据部门名称查询
     */
    public Department getByDeptName(Long companyId, String deptName) {
        return departmentMapper.getByDeptName(companyId, deptName);
    }

    /**
     * 根据部门ID查询
     */
    public Department getById(Long id) {
        return departmentMapper.selectById(id);
    }

    /**
     * 修改部门
     */
    public int update(Department department) {
        return departmentMapper.updateById(department);
    }
}